<?php require_once 'header.php'; ?>
<div class="container">
<div id="content" class="col-lg-9 clearfix">
			<?php if(isset($error)):?>
				<p class="error"><?=$error?></p>
			<?php endif;?>	
			<?php if(isset($success)):?>
				<p class="success"><?=$success?></p>
			<?php endif;?>
			<div class="grid_4">
		        <p>
		            <label>Name</label>
		            <input type="text" name="name" id="name" value="<?php if (isset($name) && $name) echo $name; ?>" />
		        </p>
		    </div> 

		    <div class="grid_4">
		        <p>
		            <label>Limit</label>
		            <select name="limit">
		                <option value="10" <?php if ($limit == 10) echo 'selected="selected"'; ?>>10</option>
		                <option value="25" <?php if ($limit == 25) echo 'selected="selected"'; ?>>25</option>
		                <option value="50" <?php if ($limit == 50) echo 'selected="selected"'; ?>>50</option>
		                <option value="100" <?php if ($limit == 100) echo 'selected="selected"'; ?>>100</option>
		                <option value="500" <?php if ($limit == 500) echo 'selected="selected"'; ?>>500</option>
		            </select>
		        </p>
		    </div>    
		    <div class="grid_2">
		        <p>
		            <label>Lọc</label>
		            <input type="button" onclick="filter();" value="Filter" />
		        </p>
		    </div>
		    <div style="clear:both"></div>
			<div class="grid_10">
				<h2>Danh sách qquảng cáo</h2>
			</div>
			<div class="grid_6" style="text-align: right;">
				<h2>
					<a href="<?php echo site_url('qlquangcao/add')?>"><img src="<?=base_url()?>styles/admin/Add.png" height="27px" /></a>
					<a href="javascript:deletetopic();"><img src="<?=base_url()?>styles/admin/Delete.png" height="27px" /></a>
				</h2>
			</div>
			<script type="text/javascript">
			function deletetopic() {
				var confirm = window.confirm('Bạn có chắc chắn xóa quảng cáo (s) này không???');
				if(!confirm) return ;
				$('#list_topic').attr('action', '<?php echo site_url('qlquangcao/delete')?>');
				$('#list_topic').submit();
			}	
		
			function removetopic(id) {
	        var conf = window.confirm('Delete this topic?');
	        if(!conf)
	            return;
	        $.ajax({
	            type: "POST",
	            data: "id=" + id,
	            url: "<?= site_url('qlquangcao/deletequangcao') ?>",
	            beforeSend: function() {
	                $("#a" + id).html("working");
	            },
	            success: function(response) {
	                var html = $.parseJSON(response);
	                alert(html.msg);
	                $("#tr" + id).hide();
	            }
	        });
    }
			</script>
			
			<form id="list_topic" method="post">
			<div class="grid_16">
				<table>
					<thead>
						<tr id = "view-pagination">
		                    <td colspan="6" align = "right" class="headt">Total quảng cáo <?=$totalquangcao?></td> 
		                    <td colspan="6" align = "left" class="headt"><?= $this->pagination->create_links() ?></td>
		                </tr>
						<tr>
							<th width="1">
								<input style="width: 5px;" type="checkbox" onclick="$('input[name*=\'selected\']').attr('checked', this.checked);" />
							</th>
							<th>Id</th>
							<th>Title</th>
                                                        <th>Link quảng cáo</th>
							<th>Create date</th>
							<th>Picture</th>
							
							<th>Prince</th>
							<th>Type</th>
							<th>Section</th>
                                                        <th>Page</th>
                                                        <td>Action</td>
						</tr>
					</thead>
					<tbody>
						<?php if($quangcao):?>
						<?php foreach($quangcao as $value):?>
						<tr id='tr<?=$value->id?>'>
							<td><input style="width: 20px;" type="checkbox" name="selected[]" value="<?=$value->id;?>" />
							<td>
								<input type="hidden" name="id[]" value="<?=$value->id?>" />
								<?=$value->id?>
							</td>
                            <td><?=$value->ads_name?></td>
                            <td><?=$value->link?></td>
                            <td><?=date('Y-m-d H:i:s', $value->upload_time)?></td>
							<td valign="middle">
								<img src='<?php echo base_url() . $value->image?>' width='60px' height='60px' style='vertical-align: middle;' />
							</td>
                                                        <td><?=$value->price ?></td>
                                                          <td><?=$value->type ?></td>
                                                           <td><?=$value->section ?></td>
							 <td><?=$value->page ?></td>
                                                         <td>
								<a href="<?php echo site_url('qlquangcao/edit/' . $value->id)?>" class="edit">Edit</a>
								<a href="javascript:;" onclick="removetopic('<?= $value->id; ?>');" class="delete" id="a<?= $value->id ?>">Delete</a>
							</td>
							
						</tr>
						<?php endforeach;?>
						<?php endif;?>
					</tbody>
				</table>
						<?php if(!$quangcao):?>
							<center>Không tìm thấy dữ liệu</center>
						<?php endif;?>
				</div>
				</form>
</div>
    </div>
<script type="text/javascript">
    function filter() {
        var url = '<?php echo site_url('qlquangcao/viewall') ?>' + '/<?php echo "$sort/$order/"; ?>' ;

        var name = $('input[name=name]').val();
        name = (name=='')?0:name;
        url += encodeURIComponent(name) + '/';
         var limit = $('select[name=limit]').val();
        url += encodeURIComponent(limit) + '/';
        //alert(url);
        window.location.href = url;
    }  
</script>
<?php require_once 'footer.php'; ?>